 	package com.jcp.dao;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.RequestParam;

import com.jcp.entity.Park;
import com.jcp.entity.Record;
import com.jcp.entity.Users;


@Repository
public interface CarOutAndOnMapper  {
	
	//判断用户是否有注册
		@Select("select * from Users where carNumber=#{carNumber}")
		List<Users> selectByCarNumber(String carNumber);
	//插入进车记录
		@Insert("insert into Record(carNumber,enter_time,paymentId)values(#{carNumber},now(),#{paymentId})")
		void insertByRecord(@Param(value="carNumber")String carNumber,@Param(value="paymentId")int paymentId);
	//对车位进行修改的方法
		@Update({"<script> " +
		        "update Park " +
		        "set" +
		        "<if test='carNumber!=null'> vip_park_space=vip_park_space-1,remaining_park_space=remaining_park_space-1</if> " +
		        "<if test='carNumber==null'>ordinary_park_space=ordinary_park_space-1,remaining_park_space=remaining_park_space-1</if>"+
				"</script>"})
		void updateByCar(String carNumber);
		
		//插入出车记录
		@Update({"<script> " +
		        "update Park " +
		        "set" +
		        "<if test='carNumber!=null'> vip_park_space=vip_park_space+1,remaining_park_space=remaining_park_space+1</if> " +
		        "<if test='carNumber==null'>ordinary_park_space=ordinary_park_space+1,remaining_park_space=remaining_park_space+1</if>"+
				"</script>"})
		void updateByCarOut(String carNumber);
		
		@Update("update Record set out_time=now(),payment_amount=#{payment_amount} where carNumber=#{carNumber} and out_time is null")
		void updateByRecordCarOut(@Param(value="payment_amount")long payment_amount,@Param(value="carNumber")String carNumber);
		
		//查询车辆时间
		@Select("select * from Record where out_time is null and carNumber=#{carNumber}")
		public Record selectByTime(@Param(value="carNumber")String carNumber);
		
		
		//扣除金额
		@Update("update Users set remainder=#{remainder} where carNumber=#{carNumber}")
		public void UpdateByMoney(@Param(value="remainder")double remainder,@Param(value="carNumber")String carNumber);
		
		
		
}
